<template>
	<sw-common-frame :count="dataCount" :loading="loading">
		<template slot="button">
			<el-button size="small" type="primary" icon="el-icon-plus" @click="handleOpenDialog()">新增</el-button>
			<el-divider direction="vertical"></el-divider>
			<el-radio-group size="small" v-model="activeName">
				<el-radio-button label="2">常量</el-radio-button>
				<el-radio-button label="1">枚举</el-radio-button>
			</el-radio-group>
		</template>
		<el-form slot="query" size="small" inline>
			<el-form-item>
				<el-input v-model="queryData.content" clearable placeholder="字典名称" style="width: 180px"></el-input>
			</el-form-item>
			<el-form-item>
				<el-input v-model="queryData.code" clearable placeholder="字典编码" style="width: 180px"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" @click="queryTableData()">查询</el-button>
			</el-form-item>
		</el-form>
		<el-table slot="table" size="medium" :data="tableData" stripe height="100%">
			<el-table-column prop="content" label="字典名称" min-width="200" show-overflow-tooltip></el-table-column>
			<el-table-column label="字典编码" min-width="200" show-overflow-tooltip>
				<template slot-scope="{ row }">
					<template v-if="row.type !== '1'">{{ row.code }}</template>
					<el-button v-else type="text" size="medium" class="enum_button" @click="handleOpenDrawer(row)">{{ row.code }}</el-button>
				</template>
			</el-table-column>
			<el-table-column prop="name" label="字典描述" min-width="200" show-overflow-tooltip></el-table-column>
			<el-table-column prop="createTime" label="创建时间" min-width="160"></el-table-column>
			<el-table-column label="操作" width="132">
				<el-button-group slot-scope="{ row }">
					<el-button size="mini" type="warning" @click="handleOpenDialog(row.id)">修改</el-button>
					<el-button size="mini" type="danger" @click="handleDeleteData(row)">删除</el-button>
				</el-button-group>
			</el-table-column>
		</el-table>
		<template slot="page">
			<sw-pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData()"></sw-pagination>
		</template>
		<form-dialog v-model="formDialog" :type="activeName" :data-id="dataId" @refresh="queryTableData()"></form-dialog>
		<dict-drawer v-model="dictDrawer" :dict-id="dataId"></dict-drawer>
	</sw-common-frame>
</template>

<script>
import dictDrawer from './data';
import formDialog from './dictForm';
import listMixins from '@/mixins/listMixins';
import { getDictDefineList, deleteDictDefine } from '@/api/system/tbSysDictDefinition';
export default {
	mixins: [listMixins],
	components: { formDialog, dictDrawer },
	data() {
		return {
			activeName: '2',
			dictDrawer: false,
			pageName: '字典定义'
		};
	},
	computed: {
		listFunction() {
			return eval(getDictDefineList);
		},
		deleteFunction() {
			return eval(deleteDictDefine);
		},
		requestParams() {
			let params = { ...this.queryData };
			params['type'] = this.activeName;
			return params;
		}
	},
	watch: {
		activeName: {
			handler() {
				this.queryTableData();
			},
			immediate: true
		}
	},
	methods: {
		//打开抽屉
		handleOpenDrawer(row) {
			this.dataId = row.id;
			this.dictDrawer = true;
		}
	}
};
</script>

<style lang="scss" scoped>
.enum_button {
	padding: 6px 0;
}
</style>
